package com.ruoyi.web.controller.tzzl;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.tzzl.domain.WzMatchmakerApply;
import com.ruoyi.tzzl.domain.WzProgramUser;
import com.ruoyi.tzzl.service.IWzMatchmakerApplyService;
import com.ruoyi.tzzl.service.IWzProgramUserService;
import io.netty.handler.codec.compression.Zstd;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.sound.midi.Soundbank;
import java.util.Date;
import java.util.List;

/**
 * 红娘申请Controller
 * @author by caoyong
 * @date 2022/11/9
 **/
@RestController
@RequestMapping("/tzzl/apply")
public class WzMatchmakerApplyController extends BaseController {

    @Autowired
    private IWzMatchmakerApplyService wzMatchmakerApplyService;

    @Autowired
    private IWzProgramUserService wzProgramUserService;

    /**
     * 查询红娘申请列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WzMatchmakerApply wzMatchmakerApply)
    {
        startPage();
        List<WzMatchmakerApply> list = wzMatchmakerApplyService.selectWzMatchmakerApplyList(wzMatchmakerApply);
        return getDataTable(list);
    }

    /**
     * 申请成为红娘
     * */
    @PostMapping("/addMatchmaker")
    public AjaxResult addMatchmaker(@RequestBody WzMatchmakerApply queryVo){
        WzProgramUser wzProgramUser = wzProgramUserService.getById(queryVo.getId());
        WzMatchmakerApply wzMatchmakerApply = new WzMatchmakerApply();
        BeanUtils.copyProperties(wzProgramUser, wzMatchmakerApply);
        wzMatchmakerApply.setStatus("0"); //待审核
        wzMatchmakerApply.setUserId(wzProgramUser.getId()); //用户id
        wzMatchmakerApply.setLocation(queryVo.getLocation()); //申请地区
        wzMatchmakerApply.setPhone(queryVo.getPhone()); //联系方式
        wzMatchmakerApply.setSex(queryVo.getSex()); //性别
        wzMatchmakerApply.setWhetherStore(queryVo.getWhetherStore()); //是否有门店
        wzMatchmakerApply.setCreateTime(new Date()); //创建时间
        return AjaxResult.success(wzMatchmakerApplyService.save(wzMatchmakerApply));
    }

    /**
     * 审批红娘申请
     * */
    @PostMapping("/matchmakerAudit")
    public AjaxResult matchmakerAudit(@RequestBody WzMatchmakerApply wzMatchmakerApply){
        return AjaxResult.success(wzMatchmakerApplyService.matchmakerAudit(wzMatchmakerApply));
    }

    /**
     * 解除红娘资格
     * */
    @PostMapping("/removeQualification")
    public AjaxResult removeQualification(@RequestBody WzMatchmakerApply wzMatchmakerApply){
        return AjaxResult.success(wzMatchmakerApplyService.removeQualification(wzMatchmakerApply));
    }

}


